/*
  学习目标：使用Action.payload传参
 
*/

import { useState } from "react";
import { useDispatch, useSelector } from "react-redux";

export default function App() {
  const [show, setShow] = useState(true);
  return (
    <div>
      <h1>Redux基础案例</h1>
      <button onClick={() => setShow(!show)}>点击切换卸载挂载</button>
      {show && <Son />}
    </div>
  );
}

function Son() {
  const count = useSelector((state) => state.count);

  const dispatch = useDispatch();

  return (
    <div>
      <h2>子组件</h2>
      <h2>count:{count}</h2>
      <button onClick={() => dispatch({ type: "add", payload: 1 })}>+1</button>
      <button onClick={() => dispatch({ type: "add", payload: 5 })}>+5</button>
      <button onClick={() => dispatch({ type: "add", payload: 10 })}>
        +10
      </button>
      <button onClick={() => dispatch({ type: "des", payload: 1 })}>-1</button>
      <button onClick={() => dispatch({ type: "des", payload: 5 })}>-5</button>
      <button onClick={() => dispatch({ type: "des", payload: 110 })}>
        -10
      </button>
    </div>
  );
}
